﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Farigola.Engine
{
    /*
     try
{
  // Run code.
}
catch(Exception ex)
{
  bool rethrow = exManager.HandleException(ex, "Logging Policy");
  if (rethrow)
    throw;
}
     * 
     */

    //*************************************************************************
    /// <summary>
    /// Represents an error, occurs in the engine.
    /// </summary>
    public class Error
    {
        /// <summary>
        /// The code to identify the error.
        /// </summary>
        public string Code { get; set; }

        // details, can be:  Le code est traduit en un text msg (traduit)
        // contient: une liste de params, (par position depuis 0)
        // une liste de code/valeur.

        // todo: hérite de Exception??
        // msg et params  (pour une gestion de trad, que code et params.
        // inner Error?
    }

    //*************************************************************************
    /// <summary>
    /// The manager of errors of the engine objects.
    /// 
    /// is reachable by the static method, to set error.
    /// </summary>
    public class ErrorMgr
    {
        private static ErrorMgr _errorMgr;

        /// <summary>
        /// only available for engine objects, object that are present in the library Farigola.Engine
        /// </summary>
        /// <returns></returns>
        internal static ErrorMgr GetErrorMgr()
        {
            if (_errorMgr == null)
                _errorMgr = new ErrorMgr();
            return _errorMgr;
        }

        /// <summary>
        /// List of error of the engine.
        /// </summary>
        private List<Error> _listError = new List<Error>();

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        public ErrorMgr()
        {
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Add a new error.
        /// </summary>
        /// <returns></returns>
        public bool Add(Error e)
        {
            if(e==null)
                return false;

            _listError.Add(e);
            return true;
        }

        // GetLastError()
        // todo: gestion du last error (de la derniere actino effectuée)
    }
}
